package org.jgs1904.practice;

import java.sql.SQLOutput;
import java.util.Scanner;

/**
 * @author: 默苍璃
 * @date: 2022-09-09 09:39
 * <p>
 * 使用switch实现一个简单的石头、剪子、布游戏。
 */
public class Switch {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("______________石头剪刀布游戏______________________");
            System.out.println("please choice:");
            System.out.println(" 1: Rock");
            System.out.println(" 2: Scissors");
            System.out.println(" 3: Paper");
            System.out.println(" 4: exit");

            int choice = scanner.nextInt();

            //退出
            if (choice == 4) {
                System.out.println("退出成功!");
                break;
            }

            //模拟电脑
            int random = 1 + (int) (Math.random() * 3);
            switch (random) {
                case 1: {
                    System.out.println("系统:1.Rock");
                    break;
                }
                case 2: {
                    System.out.println("系统:2.Scissors");
                    break;
                }
                case 3: {
                    System.out.println("系统:3.Paper");
                    break;
                }
            }

            switch (choice) {
                case 1: {
                    String result = random == 1 ? "平局" : random - choice == 1 ? "你赢了" : "你输了";
                    System.out.println("结果:" + result);
                    break;
                }
                case 2: {
                    String result = random == 2 ? "平局" : random > choice ? "你赢了" : "你输了";
                    System.out.println("结果:" + result);
                    break;
                }
                case 3: {
                    String result = random == 3 ? "平局" : choice - random == 1 ? "你输了" : "你赢了";
                    System.out.println("结果:" + result);
                    break;
                }
                default: {
                    System.out.println("输入错误");
                }
            }

        }
        scanner.close();
    }
}
